/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.training;

import javax.swing.JOptionPane;
import view.controller.training.ControllerTraining;

/**
 *
 * @author Djordje Gligorijevic
 */
public class FrmTrainingTaggerModel extends javax.swing.JDialog {

    private ControllerTraining controllerTraining;

    /**
     * Creates new form FrmTrainingTaggerModel
     */
    public FrmTrainingTaggerModel(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cbCorpuses = new javax.swing.JComboBox();
        btnStartTraining = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtATrainingResults = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Named entity recognition training");
        setResizable(false);

        jLabel1.setText("Choose corpus to train named entity recognition model on it:");

        btnStartTraining.setText("Start training");
        btnStartTraining.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartTrainingActionPerformed(evt);
            }
        });

        txtATrainingResults.setColumns(20);
        txtATrainingResults.setRows(5);
        txtATrainingResults.setText("You will see results of the training here.");
        jScrollPane1.setViewportView(txtATrainingResults);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(288, Short.MAX_VALUE))
            .addComponent(jScrollPane1)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnStartTraining, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbCorpuses, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(144, 144, 144))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbCorpuses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(btnStartTraining)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnStartTrainingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartTrainingActionPerformed
        try {
            controllerTraining.startTraining();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage());
            txtATrainingResults.setText("There was an error during training:\n" + ex.getMessage());
        }
    }//GEN-LAST:event_btnStartTrainingActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmTrainingTaggerModel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmTrainingTaggerModel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmTrainingTaggerModel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmTrainingTaggerModel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FrmTrainingTaggerModel dialog = new FrmTrainingTaggerModel(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnStartTraining;
    private javax.swing.JComboBox cbCorpuses;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txtATrainingResults;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the controllerTraining
     */
    public ControllerTraining getControllerTraining() {
        return controllerTraining;
    }

    /**
     * @param controllerTraining the controllerTraining to set
     */
    public void setControllerTraining(ControllerTraining controllerTraining) {
        this.controllerTraining = controllerTraining;
    }

    /**
     * @return the btnStartTraining
     */
    public javax.swing.JButton getBtnStartTraining() {
        return btnStartTraining;
    }

    /**
     * @param btnStartTraining the btnStartTraining to set
     */
    public void setBtnStartTraining(javax.swing.JButton btnStartTraining) {
        this.btnStartTraining = btnStartTraining;
    }

    /**
     * @return the cbCorpuses
     */
    public javax.swing.JComboBox getCbCorpuses() {
        return cbCorpuses;
    }

    /**
     * @param cbCorpuses the cbCorpuses to set
     */
    public void setCbCorpuses(javax.swing.JComboBox cbCorpuses) {
        this.cbCorpuses = cbCorpuses;
    }

    /**
     * @return the jLabel1
     */
    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    /**
     * @param jLabel1 the jLabel1 to set
     */
    public void setjLabel1(javax.swing.JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    /**
     * @return the jScrollPane1
     */
    public javax.swing.JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    /**
     * @param jScrollPane1 the jScrollPane1 to set
     */
    public void setjScrollPane1(javax.swing.JScrollPane jScrollPane1) {
        this.jScrollPane1 = jScrollPane1;
    }

    /**
     * @return the txtATrainingResults
     */
    public javax.swing.JTextArea getTxtATrainingResults() {
        return txtATrainingResults;
    }

    /**
     * @param txtATrainingResults the txtATrainingResults to set
     */
    public void setTxtATrainingResults(javax.swing.JTextArea txtATrainingResults) {
        this.txtATrainingResults = txtATrainingResults;
    }

    public void updateForm() {
        controllerTraining.getCorpusesComboBox();
    }
}
